<?php
/**
 *
 * 主加载
 *
 * @author		Tata <windzb@qq.com>
 */

class Loader {

	/**
	 * 列表记录已经加载的类
	 *
	 * @var array
	 * @access protected
	 */
	protected $_classes = array();


	// --------------------------------------------------------------------

	/**
	 * Is Loaded
	 *
	 */
	public function is_loaded($class)
	{
		if (isset($this->_classes[$class]))
		{
			return $this->_classes[$class];
		}

		return FALSE;
	}


	public static function load_class($name, $directory = 'models/mac')
	{
		$TATA =& get_instance();
		$class = $TATA->load->is_loaded($name);

		if($class == FALSE)
		{
			//由于TAE不允许使用file_exsits函数 暂不判断文件是否存在
			//if (file_exsits(SYS_PATH.'/'.$directory.'/'.$class.'.php'))
			{
				require_once(SYS_PATH.'/php/'.$directory.'/'.$name.'.php');
				$class = new $name();
				$TATA->load->_classes[$name] =& $class;
			}
		}

		//返回实例
		return  $class;
	}


	//加载dao
	public static function mdl($class)
	{
		return self::load_class($class,"models/mac");
	}

	//加载etry
	public static function enty($class)
	{
		return self::load_class($class,"models/entity");
	}

	//加载top模型
	public static function top($class)
	{
		return self::load_class($class,"models/top");
	}

	//加载lib
	public static function lib($class)
	{
		return self::load_class($class,"libs");
	}

	//加载API
	public static function api($class)
	{
		return self::load_class($class,"libs/api/top");
	}
	/*//加载wantu
	public static function wantu($class)
	{
		return self::load_class($class,"libs/wantu/alimedia");
	}*/


}
